;##################################
;命令：
;nasm -f elf64 day32_case1__3_12_5_14__10_9_4_6.asm -o main.o && gcc main.o -o main -lc -no-pie && ./main
;输出：
;Value in arr[0] is 13.333300.
;Value in arr[1] is 22.222099.
;Value in arr[2] is 9.999900.
;Value in arr[3] is 21.111000.
;##################################
extern printf

section .data
	msg: db `Value in arr[%d] is %f.\n`, 0
	arr: dd 0.0000, 1.1111, 2.2222, 3.3333, 4.4444, 5.5555, 6.6666, 7.7777, 8.8888, 9.9999, 10.0000, 11.1111, 12.2222, 13.3333, 14.4444, 15.5555

section .text
	global main

main:
	push rbp
	mov rbp, rsp

;####################################################################################
	;void foo(float *a) {
	;    a[20] = a[3] + a[10];
	;    a[21] = a[12] + a[9];
	;    a[22] = a[5] + a[4];
	;    a[23] = a[14] + a[6];
	;}
	;a[3] a[4] a[5] a[6]
	vmovups xmm0, [arr + 4 * 3]
	;a[9] a[10] a[12] a[14]
	vmovsd xmm1, [arr + 4 * 9]
	vmovss xmm2, [arr + 4 * 12]
	vinsertps xmm2, [arr + 4 * 14], 10h
	vmovlhps xmm1, xmm1, xmm2
	;a[9] a[12] a[10] a[14]
	vshufps xmm1, xmm1, 11011000b
	;a[3] a[12] a[5] a[14]
	vblendps xmm2, xmm0, xmm1, 1010b
	;a[10] a[9] a[4] a[6]
	vshufps xmm1, xmm1, xmm0, 11010010b
	;加法
	vaddps xmm1, xmm1, xmm2
	vmovups [arr], xmm1
;####################################################################################

	;打印
	mov ebx, 0
	jmp compare

execute:
	mov rdi, msg
	movsxd rsi, ebx
	cvtss2sd xmm0, dword [arr + 4 * ebx]
	movq rdx, xmm0
	call printf

	inc ebx

compare:
	cmp ebx, 4
	jl execute

	mov eax, 0
	leave
	ret
